;(function() {
  'use strict';
  angular.module('controllers.oldOMDisplay.pbossOm')
    .controller('resourceUseRateController', resourceUseRateController);
  function resourceUseRateController($scope,System,resourceUseRateService,odOperationDevelop,CoreService){
  	$scope.sysNames = System;
  	$scope.regions = resourceUseRateService.getRegion();
  	$scope.netWorkEquipment = resourceUseRateService.getNetWorkEquipment();
  	$scope.timeTypes = resourceUseRateService.getTimeType();
  	$scope.sendData = resourceUseRateService.getPageBind();
  	//控制查询条件拉上拉下   1为拉下  0 为拉上
		$scope.shoumun = {
			num: 1
		};
		//监控帐期，选择不同的帐期，给开始时间和结束时间不同的默认值
		var year = new Date().getFullYear();
		var month = new Date().getMonth();
		var day = new Date().getDate();
		var hour = new Date().getHours();
		$scope.$watch('sendData.timeType', function(newValue) {
			switch (newValue) {
				case '1':
					$scope.sendData.startTime = new Date(year, month, day-7);
					$scope.sendData.endTime = new Date(year, month, day);
					break;
				case '0':
					$scope.sendData.startTime = new Date(year, month, day, hour-7);
					$scope.sendData.endTime = new Date(year, month, day, hour);
			}
		});
		//控制等待样式   false 为隐藏   true 为显示
		$scope._loading.show = false;
		$scope.search = function(){
			if ($scope.shoumun.num === 1) {
				$scope.shoumun.num = 1;
				return;
			}
			$scope._loading.show = true;
			$scope.send = {
				regionName:[]
			};
			if($scope.sendData.timeType === '1'){
				$scope.send.timeType = '1';
				$scope.send.startTime = CoreService.dateFormat($scope.sendData.startTime, 'yyyy-MM-dd');
				$scope.send.endTime = CoreService.dateFormat($scope.sendData.endTime, 'yyyy-MM-dd');
			}else if($scope.sendData.timeType === '0'){
				$scope.send.timeType = '0';
				$scope.send.startTime = CoreService.dateFormat($scope.sendData.startTime, 'yyyy-MM-dd hh');
				$scope.send.endTime = CoreService.dateFormat($scope.sendData.endTime, 'yyyy-MM-dd hh');
			}
			$scope.time = '';
			if($scope.send.startTime === $scope.send.endTime){
				$scope.time = $scope.send.startTime.replace(/-/g,'');
			}else {
				$scope.time = $scope.send.startTime.replace(/-/g,'') +' _ '+$scope.send.endTime.replace(/-/g,'');
			}
			var title = '防火墙';
			$scope.send.systemCode = $scope.sendData.system;
			if($scope.sendData.region.length !== 0){
				$scope.send.regionName = $scope.sendData.region.map(function(reg){
					return reg.regionName;
				});
			}
			resourceUseRateService.queryNetworkDevice($scope.send,function(res){
				if(res.state === '10000'){
					resourceUseRateService.getData(res,$scope.time,title);
					$scope._loading.show = false;
					$scope.flag = 'view';
				}else if(res.cpu.length === 0){
					$scope.flag = '';
					$scope._loading.show = true;
					CoreService.dialog('当前查询无数据');
				}else {
					$scope._loading.show = true;
					CoreService.dialog('查询错误');
				}
			});
		};
		$scope.queryRouter = function(){
			$scope._loading.show = true;
			var title = '路由器';
			resourceUseRateService.queryNetworkRouter($scope.send,function(res){
				if(res.state === '10000'){
					resourceUseRateService.getData(res,$scope.time,title);
					$scope._loading.show = false;
					$scope.flag = 'view';
				}else if(res.cpu.length === 0){
					$scope.flag = '';
					$scope._loading.show = true;
					CoreService.dialog('当前查询无数据');
				}else {
					$scope._loading.show = true;
					CoreService.dialog('查询错误');
				}
			});
		};
		$scope.queryNetworkExchangeMachine = function(){
			$scope._loading.show = true;
			var title = '交换机';
			resourceUseRateService.queryNetworkExchangeMachine($scope.send,function(res){
				if(res.state === '10000'){
					resourceUseRateService.getData(res,$scope.time,title);
					$scope._loading.show = false;
					$scope.flag = 'view';
				}else if(res.cpu.length === 0){
					$scope.flag = '';
					$scope._loading.show = true;
					CoreService.dialog('当前查询无数据');
				}else {
					$scope._loading.show = true;
					CoreService.dialog('查询错误');
				}
			});
		};
  }
})();